#ifndef NETWORKCONTROLLER_H
#define NETWORKCONTROLLER_H

#include <QObject>
#include <QtNetwork>
#include "Config.h"


class NetWorkController:public QObject
{
    Q_OBJECT
public:
    static NetWorkController* getInstance(){
        return &instance;
    }
    void m_connetToServer();
    void m_sendLoginMessage(const QString &username ,const QString &password);
    QString generateCaptcha();                                           //生成随机验证码
    bool sendCaptchaEmail(const QString& recipient, const QString& captcha);
    void sendRegisterMessage(const QString &username , const QString &password);
    bool sendAddFrdMessage(const QString &username);
    bool sendChatMessage(const QString &username , const QString &text);

    bool getIsConnect() const;
    void setIsConnect(bool newIsConnect);
    static QJsonObject parserStr(QString str);
    QTcpSocket *getCSocket() const;
    void setCSocket(QTcpSocket *newCSocket);
public slots:
    void client_Recv();
signals:
    void sendFriendInfo(QJsonArray jobj);
    void sendMsgSig(const QString &username,const QString &message);

private:
     NetWorkController();
     static NetWorkController instance;
     QTcpSocket *cSocket = new QTcpSocket();
     bool isConnect;
};

#endif // NETWORKCONTROLLER_H
